<?php

abstract class AlertMode {
    const Success = 'alert-success';
    const Error = 'alert-error';
    const Warning = null;
    const Information = 'alert-info';
}

class Alert extends QPanel {

    private $objShowAction, $objHideAction;
    public $strTitle, $strMessage;
    public $btnClose;

    public function __construct($objParentObject, $strControlId = null) {
        parent::__construct($objParentObject, $strControlId);

        $this->DisplayStyle = QDisplayStyle::None;

        $this->Template = __DOCROOT__ . __SUBDIRECTORY__ . '/admin/view/shared/alert.tpl.php';

        $this->objShowAction = new QJQShowAction($this, 'slow');
        $this->objHideAction = new QJQHideAction($this, 'slow');

        $this->btnClose = new QButton($this);
        $this->btnClose->Text = '×';
        $this->btnClose->AddAction(new QClickEvent(), $this->objHideAction);
        $this->btnClose->AddAction(new QClickEvent(), new QTerminateAction());
    }

    public function Success($strTitle, $strMessage) {
        $this->DisplayAlert($strTitle, $strMessage, AlertMode::Success);
    }

    public function Warning($strTitle, $strMessage) {
        $this->DisplayAlert($strTitle, $strMessage, AlertMode::Warning);
    }

    public function Information($strTitle, $strMessage) {
        $this->DisplayAlert($strTitle, $strMessage, AlertMode::Information);
    }

    public function Error($strTitle, $strMessage) {
        $this->DisplayAlert($strTitle, $strMessage, AlertMode::Error);
    }

    private function DisplayAlert($strTitle, $strMessage, $strAlertMessageMode) {

        $this->CssClass = sprintf('alert alert-block %s', $strAlertMessageMode);

        $this->strTitle = $strTitle;
        $this->strMessage = $strMessage;

        QApplication::ExecuteJavaScript($this->objHideAction->RenderScript($this));
        QApplication::ExecuteJavaScript($this->objShowAction->RenderScript($this));
    }

}

?>